package com.linked.goods.shop.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.linked.goods.goodsbase.bean.po.GoodsInfoPO;
import com.linked.goods.shop.bean.dto.ShopDTO;
import com.linked.goods.shop.bean.po.ShopInfoPO;
import com.linked.goods.shop.service.IShopService;
import com.linked.universal.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :dbq
 * @date : 2023/5/25 10:12
 * @description : desc
 */
@RestController
@Slf4j
@RequestMapping("/shop")
public class ShopController {

    private final IShopService shopService;

    private final ObjectMapper mapper;

    public ShopController(IShopService shopService, ObjectMapper mapper) {
        this.shopService = shopService;
        this.mapper = mapper;
    }

    @PostMapping("addShop")
    Result addShop(@RequestBody ShopDTO param) throws Exception {
        if (log.isInfoEnabled()) {
            log.info("添加店铺接口 入参：{}", mapper.writeValueAsString(param));
        }
        boolean ret = false;
        try {
            ret = shopService.addShop(new ShopInfoPO(param));
        } catch (Exception e) {
            log.error("添加店铺接口 异常！", e);
            return Result.error("未知异常，请联系管理员!");
        }
        return !ret ? Result.ok(false, "保存失败！") : Result.success();
    }
}
